﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AssignmentSWEN3.App_Code;

namespace AssignmentSWEN3
{
    public partial class HouseKeepingUpdate : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {

                string staffID = Request.QueryString["staffID"];
                //get query string 
                int staffOID = Convert.ToInt32(staffID);
                Staff k = DataManager.GetStaffByID(staffOID);
                DateTime dob = Convert.ToDateTime(DropDownList2.Text + DropDownList3.Text + TextBox9.Text);
                TextBox15.Text = k.StaffOID.ToString();
                tbxName.Text = k.Name;
                dob = k.Dob;
                DropDownList2.SelectedItem.Text = k.Dob.Day.ToString();
                string[] month = { "January", "February", "March", "May", "June", "July", "August", "September", "October", "November", "December" };
                int monthnumber = k.Dob.Month;
                for (int i = 0; i < month.Length; i++)
                {
                    if ((monthnumber - 1) == i)
                    {
                        DropDownList3.SelectedItem.Text = month[i];
                    }
                }
                TextBox9.Text = k.Dob.Year.ToString();
                TextBox10.Text = k.BankAccNum;
                TextBox11.Text = k.Address;
                TextBox12.Text = k.PhoneNum.ToString();
                TextBox13.Text = k.Email;
                TextBox14.Text = k.Password;
                DropDownList1.SelectedValue = k.DutyType;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Staff m = new Staff();
            m.StaffOID = (int)Convert.ToInt32(TextBox15.Text);
            m.Name = tbxName.Text;
            m.Dob = Convert.ToDateTime(DropDownList2.SelectedValue + "/" + DropDownList3.SelectedValue + "/" + TextBox9.Text);
            m.BankAccNum = TextBox10.Text;
            m.Address = TextBox11.Text;
            m.Email = TextBox13.Text;
            m.Password = TextBox14.Text;
            m.PhoneNum = (int)Convert.ToInt32(TextBox12.Text);
            m.DutyType = DropDownList1.SelectedValue;


            //display message of success or failure to user 
            if (DataManager.UpdateStaff(m) == 1)
            {
                lblStatus.Text = (" Details updated successfully");

            }
            else
            {
                lblStatus.Text = ("Update fail, Staff ID cannot be changed");
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("HouseKeepingView.aspx?");
        }
    }
}